//	ID : pallab81
// 	PROG : 116
// 	LANG : C++
// 	2011-08-30-14.11.43 Tuesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int R,C;
vector< VI > g;
vector< VI > dp;
inline void Read(){
    g.assign(R,VI(C,0));
    fo(i,0,R){
        fo(j,0,C){
            CI(g[i][j]);
        }
    }
}
int go(int r, int c){
    if(c==C){
        return 0;
    }
    if(dp[r][c]!=-1){
        return dp[r][c];
    }

    int tr1 = r-1 < 0 ? R-1 : r-1;
    int tr2 = r+1 == R? 0 : r+1;
    int tr3 = r;

    int one = go(tr1, c+1);
    int two = go(tr2, c+1);
    int three = go(tr3, c+1);

    int best = g[r][c]+min(one, min(two, three));
    dp[r][c]=best;

return best;
}
inline void back_track(int r, int c){
    if(c==C){
        return ;
    }
    int tr1 = r-1 < 0 ? R-1 : r-1;
    int tr2 = r+1 == R? 0 : r+1;
    int tr3 = r;

    int one = go(tr1, c+1);
    int two = go(tr2, c+1);
    int three = go(tr3, c+1);

    vector< pair<int,int> > vp;
    vp.pb( mk(one,tr1) );
    vp.pb( mk(two,tr2) );
    vp.pb( mk(three,tr3) );

    sort(vp.begin(),vp.end(), less< pair<int,int> >() );

    if(c+1<C){
        printf(" %d",vp[0].s+1);
    }
    back_track(vp[0].s,c+1);

}

inline void Proc(){
    dp.assign(R,VI(C,-1));
    int best = (int)1023456789;
    int row;
    fo(i,0,R){
        int var = go(i,0);
        if( var < best ){
            best = var;
            row = i;
        }
    }
    cout<<row+1;
    back_track(row,0);
    cout<<"\n"<<best<<"\n";
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif

    while( scanf("%d %d",&R,&C)==2 ){
        Read();
        Proc();
    }
return 0;
}
